<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-input class="filter-item" @keyup.enter.native="handleFilter" style="width: 200px;" placeholder="请输入关键词" v-model="search.keyword"></el-input>
      <div class="filter-item">
        <span class="txt">添加时间</span>
        <el-date-picker style="width: 240px;" value-format="timestamp" v-model="search.date" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <el-button class="filter-item" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <div style="color: #666; margin-bottom: 10px;">累计金额：{{sum}}</div>
    <el-table v-loading="!pload" ref="multipleTable" border :data="tableData">
      <el-table-column property="userName" label="用户名" show-overflow-tooltip></el-table-column>
      <el-table-column property="phone" label="手机号" show-overflow-tooltip></el-table-column>
      <el-table-column property="authType" label="用户类型" show-overflow-tooltip></el-table-column>
      <el-table-column property="amount" label="奖励金（中亿币）" show-overflow-tooltip></el-table-column>
      <el-table-column property="dayNum" label="连续签到次数" show-overflow-tooltip></el-table-column>
      <el-table-column property="payText" label="状态" show-overflow-tooltip></el-table-column>
      <el-table-column property="url" label="时间" show-overflow-tooltip width="200">
        <template slot-scope="scope">
          <span>{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</span>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-size="limit" :page-sizes="limits" background layout="sizes, prev, pager, next, jumper, total" :total="count">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import * as api from '@/utils/api'
import waves from '@/directive/waves' // 水波纹指令
export default {
  directives: {
    waves
  },
  data () {
    return {
      tableData: [],
      search: {
        keyword: ''
      },
      pload: false,
      currentPage: 1,
      sum: null,
      limit: 10,
      limits: [10, 20, 50, 100],
      count: 0
    }
  },
  computed: {
    roomId () {
      return this.$route.query.id
    }
  },
  created () {
    this.getData()
  },
  methods: {
    async handleTj (index, row) {
      this.$confirm('确认要' + ['正常', '禁言'][row.status] + '吗', { type: 'warning' }).then(async () => {
        try {
          this.pload = false
          await api.tjZBfans({ ids: row.id, roomId: row.roomId, status: row.status ? 0 : 1 })
          this.$notify({ title: '操作成功', type: 'success', duration: 5000 })
          this.getData()
        } catch (e) {
          this.pload = true
        }
      })
    },
    async getData () {
      if (this.search.date) {
        this.search.searchStartTime = this.search.date[0]
        this.search.searchEndTime = this.search.date[1]
      } else {
        delete this.search.searchStartTime
        delete this.search.searchEndTime
      }
      const data = { pageNum: this.currentPage, pageSize: this.limit, ...this.search, roomId: this.roomId }
      this.pload = false
      const Datas = await api.getLtsCheckIn(data)
      this.tableData = Datas.pageInfo.list
      this.sum = Datas.sumAmount
      this.count = Datas.pageInfo.total
      this.pload = true
    },
    handleFilter () {
      this.currentPage = 1
      this.getData()
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.limit = val
      this.getData()
    },
    handleCurrentChange (val) {
      this.currentPage = val
      this.getData()
    }
  }
}
</script>
